import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:woniutaofang/components/ui/image_load_view.dart';
import 'package:woniutaofang/pages/home/home_router.dart';
import 'package:woniutaofang/routers/fluro_navigator.dart';
import 'package:woniutaofang/utils/dimens.dart';

// ignore: must_be_immutable
class HouseCenterWidget extends StatefulWidget {
  HouseCenterWidget({Key key, this.list}) : super(key: key);
  List list;

  @override
  _HouseCenterWidgetState createState() => _HouseCenterWidgetState();
}

class _HouseCenterWidgetState extends State<HouseCenterWidget> {
  Widget buildGrid() {
    List<Widget> tiles = []; //先建一个数组用于存放循环生成的widget
    Widget content; //单独一个widget组件，用于返回需要生成的内容widget
    for (var item in widget.list) {
      tiles.add(
        Container(
          height: 130,
          decoration: BoxDecoration(
            border: Border(
              bottom: BorderSide(
                width: 0.5,
                color: Colors.grey[100],
              ),
            ),
          ),
          padding: EdgeInsets.only(bottom: 15, top: 15),
          child: InkWell(
            onTap: () => NavigatorUtils.pushResult(
                context, '${HomeRouter.homeProperty}?id=${item.projectId}',
                (result) {
              print('result$result');
            }),
            // Application.router
            //     .navigateTo(context, '/property/${item.projectId}')
            //     .then((val) {
            //   print('val$val');
            // }),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Expanded(
                  flex: 4,
                  child: Stack(
                    children: <Widget>[
                      Hero(
                        tag: item.projectId,
                        child: ImageLoadView(
                          item.path,
                          width: 150,
                          height: 130,
                          fit: BoxFit.fill,
                          radius: 6.0,
                        ),
                      ),
                      Positioned(
                        left: 0,
                        top: 0,
                        child: Container(
                          width: ScreenUtil().setWidth(60),
                          height: ScreenUtil().setHeight(40),
                          decoration: BoxDecoration(
                            color: Colors.red,
                            borderRadius: BorderRadius.all(
                              Radius.circular(5),
                            ),
                          ),
                          child: Center(
                            child: Text(
                              '在售',
                              style:
                                  TextStyle(color: Colors.white, fontSize: 12),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(
                  width: 10,
                ),
                Expanded(
                  flex: 8,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisSize: MainAxisSize.max,
                    children: <Widget>[
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Flexible(
                            child: Container(
                              width: ScreenUtil().setWidth(300),
                              child: Text(
                                '德很困难的的接口参数',
                                overflow: TextOverflow.ellipsis, //长度溢出后显示省略号
                                style: TextStyle(
                                  fontSize: 16.0,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                          ),
                          Text(
                            '5651人想买',
                            style:
                                TextStyle(fontSize: 12.0, color: Colors.grey),
                          ),
                        ],
                      ),
                      // Gaps.vGap3,
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Flexible(
                            child: Container(
                              width: ScreenUtil().setWidth(250),
                              child: Text(
                                '商业综合体是几点开考',
                                overflow: TextOverflow.ellipsis, //长度溢出后显示省略号
                                style: TextStyle(
                                  fontSize: 14.0,
                                ),
                              ),
                            ),
                          ),
                          Text(
                            '浦口区—江浦街道',
                            style: TextStyle(fontSize: 12.0),
                          ),
                        ],
                      ),
                      // Gaps.vGap3,
                      Row(
                        children: <Widget>[
                          _GoodsItemTag(
                            text: '待定',
                            color: Theme.of(context).errorColor,
                          ),
                          SizedBox(
                            width: ScreenUtil().setWidth(20),
                          ),
                          Text(
                            '建面37m-121m',
                            style:
                                TextStyle(fontSize: 14.0, color: Colors.grey),
                          )
                        ],
                      ),
                      // Gaps.vGap3,
                      Row(
                        children: <Widget>[
                          Container(
                            height: 22.0,
                            padding: EdgeInsets.all(2),
                            decoration: BoxDecoration(
                              color: Colors.green[50],
                              borderRadius: BorderRadius.all(
                                Radius.circular(5),
                              ),
                            ),
                            child: Center(
                              child: Text(
                                '精致改善',
                                style: TextStyle(
                                  fontSize: 12.0,
                                  color: Colors.green[500],
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: ScreenUtil().setWidth(20),
                          ),
                          Container(
                            height: 22.0,
                            padding: EdgeInsets.all(2),
                            decoration: BoxDecoration(
                              color: Colors.green[50],
                              borderRadius: BorderRadius.all(
                                Radius.circular(5),
                              ),
                            ),
                            child: Center(
                              child: Text(
                                '甜蜜安家',
                                style: TextStyle(
                                  fontSize: 12.0,
                                  color: Colors.green[500],
                                ),
                              ),
                            ),
                          ),
                        ],
                      )
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
      );
    }
    content = Column(children: tiles);
    return content;
  }

  @override
  Widget build(BuildContext context) {
    return buildGrid();
  }
}

class _GoodsItemTag extends StatelessWidget {
  const _GoodsItemTag({
    Key key,
    this.color,
    this.text,
  }) : super(key: key);

  final Color color;
  final String text;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 4.0),
      margin: const EdgeInsets.only(right: 4.0),
      decoration: BoxDecoration(
        color: color,
        borderRadius: BorderRadius.circular(2.0),
      ),
      height: 16.0,
      alignment: Alignment.center,
      child: Text(
        text,
        style: const TextStyle(
          color: Colors.white,
          fontSize: Dimens.font_sp10,
        ),
      ),
    );
  }
}
